package com.beiji.usercentert.comoon;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回结果
 * @param <T>
 */
@Data
public class BaseResponse<T> implements Serializable {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 数据
     */
    private T data;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 详细信息
     */
    private String description;

    //无参成功
    public static <T> BaseResponse<T> success(){
        BaseResponse<T> response = new BaseResponse<T>();
        response.setCode(200);
        return response;
    }

    //有参成功
    public static <T> BaseResponse<T> success(T data){
        BaseResponse<T> response = new BaseResponse<T>();
        response.setCode(200);
        response.setData(data);
        return response;
    }

    //失败
    public static <T> BaseResponse<T> error(ErrorCode errorCode){
        BaseResponse<T> response = new BaseResponse<T>();
        response.setCode(errorCode.getCode());
        response.setMessage(errorCode.getMessage());
        return response;
    }

    //详细错误
    public static <T> BaseResponse<T> error(ErrorCode errorCode, String description){
        BaseResponse<T> response = new BaseResponse<T>();
        response.setCode(errorCode.getCode());
        response.setMessage(errorCode.getMessage());
        response.setDescription(description);
        return response;
    }



}
